<template>
    <view>
        <view class="commentFrame">
            <uni-easyinput ref="uipt" @confirm="goComment" suffixIcon="paperplane" v-model="replyContent"
                :placeholder="placeholder" @iconClick="goComment">
            </uni-easyinput>
        </view>
    </view>
</template>

<script setup>
    import {
        ref
    } from 'vue';
    import {
        getProvince
    } from '../../uitls/tools.js'
    let replyContent = ref('');
    const db = uniCloud.database();
    const props = defineProps(['commentObj']);
    const emits = defineEmits(['toParant']);
    let utils = uniCloud.importObject('utiltsObj', {
        customUI: true
    });
    //发送评论
    async function goComment() {
        console.log(props.commentObj);
        if (replyContent.value) {
            let province = await getProvince();
            db.collection('quanzi_comment').add({
                comment_content: replyContent.value,
                province,
                ...props.commentObj
            }).then(res => {
                emits('toParant', {
                    _id: res.result.id,
                    province,
                    comment_content: replyContent.value,
                    comment_date: Date.now(),
                })
                replyContent.value = '';
                utils.opration('fyquanzi_art', 'comment_count', props.commentObj.article_id, 1)
            })
        }
    }
</script>

<style lang="scss" scoped>
    .commentFrame {
        width: 100%;
        background: #fff;
        padding: 20rpx 30rpx;
        box-sizing: border-box;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 100;
    }
</style>